Python: fix: preserve explicit null tool arguments#5997
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Python tool-invocation bug where explicitly provided null/None arguments were being dropped after Pydantic validation, causing required-but-nullable tool parameters to be omitted (notably in auto function-calling flows).
Changes:
- Introduces
_dump_tool_arguments()to keepexclude_none=Truebehavior while re-including explicitly-suppliedNonefields. - Updates
FunctionTool.invoke()and the auto function-call execution path to use_dump_tool_arguments(). - Adds regression tests covering both direct
FunctionTool.invoke()and automatic function-call execution.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/packages/core/agent_framework/_tools.py | Adds _dump_tool_arguments() and uses it in tool invocation and auto function-call execution to preserve explicit null arguments. |
| python/packages/core/tests/core/test_tools.py | Adds a regression test ensuring direct invoke() preserves explicitly provided None for a required nullable parameter. |
| python/packages/core/tests/core/test_function_invocation_logic.py | Adds a regression test ensuring auto function calling preserves null arguments from model-generated function calls. |
Comment on lines
+242
to
+243
| for name in include_none_from if include_none_from is not None else model.model_fields_set: | ||
| if getattr(model, name, None) is None: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nulltool arguments after Pydantic validationFunctionTool.invoke()and automatic function-call executionexclude_nonebehavior for fields that were not explicitly suppliedFixes #5934.
Validation